import { getAreaOptions, getTreeOptions } from '@/common/api/public/public.js'
export default {
  state: {
    areaOptions: null,
    treeOptions: null
  },
  mutations: {
    // 添加一个 mutation 用来更新 state 中的 areaOptions
    SET_AREA_OPTIONS(state, options) {
      state.areaOptions = options
    },
    SET_TREE_OPTIONS(state, options) {
      state.treeOptions = options
    }
  },
  actions: {
    getAreaOptionsState({ commit }) {
      getAreaOptions()
        .then(result => {
          if (!result.value?.length) {
            return
          }
          let value = result.value
          value = value.map(item => {
            return {
              label: item.provName,
              value: item.provCode
            }
          })
          value.shift()
          // console.log(value, 'value')
          commit('SET_AREA_OPTIONS', value)
        })
        .catch(error => {
          console.error('获取省失败', error)
        })
    }
  }
}
